package com.weiyin.examination.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.weiyin.examination.R;

import java.util.List;

/**
 * @author lenovo
 * @date 2017/11/24
 */

public class FlatSharpAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {
    public FlatSharpAdapter(@LayoutRes int layoutResId, @Nullable List<Integer> data) {
        super(layoutResId, data);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        /**
         * item点击事件
         *
         * @param holder   BaseViewHolder
         * @param position position
         */
        void onItemClick(BaseViewHolder holder, int position);
    }

    @Override
    protected void convert(final BaseViewHolder helper, Integer item) {
        if (item != null) {
            helper.setImageResource(R.id.flatSharpItemImageView, item);
        }
        helper.getView(R.id.flatSharpItemLayout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(helper, helper.getAdapterPosition());
                }
            }
        });
    }
}
